package com.zyd;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.facebook.react.modules.core.PermissionListener;

public class MainActivity extends ReactActivityMy {
    private PermissionListener listener;
    private View mRootView;

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "ZYD";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //初始化rnrootview
        super.onCreate(savedInstanceState);
        //获取rnrootview
        mRootView = getRootView();
        //模拟loadding图片
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                setContentView(mRootView);
//            }
//        }, 3000);

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                mRootView.setVisibility(View.VISIBLE);
//                Toast.makeText(MainActivity.this, "显示页面了", Toast.LENGTH_SHORT).show();
                setContentView(mRootView);

            }
        }, new IntentFilter("com.demo.show"));
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (listener != null)
        {
            listener.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
